package com.txzt.gaea.business.project.controller;

import com.txzt.base.core.RtnInfo;
import com.txzt.gaea.business.plan.domain.query.PlanInfoQuery;
import com.txzt.gaea.business.project.domain.model.ProjectLog;
import com.txzt.gaea.business.project.service.IProjectLogService;
import com.txzt.gaea.business.util.TranslateUtil;
import com.txzt.gaea.common.base.controller.BaseController;
import com.txzt.gaea.flow.service.FlowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/project/log")
public class ProjectLogController extends BaseController {

    @Autowired
    private IProjectLogService projectLogService;
    @Autowired
    private FlowService flowService;

    /**
     * 分页查询
     * @param pageNumber
     * @param pageSize
     * @param planInfoQuery
     * @return
     */
    @GetMapping(value = "/list")
    public RtnInfo<?> pageList(@RequestParam(defaultValue = "1") Integer pageNumber,
                               @RequestParam(defaultValue = "10") Integer pageSize, PlanInfoQuery planInfoQuery) {
        return null;
    }

    /**
     * 查询项目审核日志
     * @param flowId
     * @return
     */
    @GetMapping(value = "/queryByFlowId")
    public RtnInfo<?> queryLog(@RequestParam Long flowId) {
        List<ProjectLog> list = projectLogService.getProjectLogByFlowId(flowId);
        list.forEach(l ->{
            //翻译操作人
            l.setCreateName(TranslateUtil.getUserName(l.getCreateBy()));
            //获取审核步骤
            l.setStepList(flowService.getFlowBizStep(l.getFlowId()));
        });
        return RtnInfo.success(list);
    }

    /**
     * 查询项目审核日志
     * @param id
     * @param operateType
     * @return
     */
    @GetMapping(value = "/queryLog")
    public RtnInfo<?> queryLog(@RequestParam Long id,@RequestParam Integer operateType) {
        List<ProjectLog> list = projectLogService.getProjectLog(id,operateType);
        list.forEach(l ->{
            //翻译操作人
            l.setCreateName(TranslateUtil.getUserName(l.getCreateBy()));
            //获取审核步骤
            l.setStepList(flowService.getFlowBizStep(l.getFlowId()));
        });
        return RtnInfo.success(list);
    }

}
